<!-- 
This stylesheet has been tested with Microsoft IE 5.0 
and MSXML30 SP1 in REPLACE MODE (use xmlinst.exe)
Search "Installing MSXML 3.0 for XSLT Support" in the MSDN Library
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
   
   <xsl:template match="/">
   
      <html>
         <head>
            <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
            <title><xsl:value-of select="'Documentation'" /></title>
			<link rel="stylesheet" type="text/css" href="http://i3.msdn.microsoft.com/Combined.css?resources=0:Topic,1:CodeSnippet,1:ProgrammingSelector,1:ExpandableCollapsibleArea,1:CommunityContent,0:TopicNotInScope,1:FeedViewerBasic,2:LibrarySprite,3:epxheader.2,4:sharethis.1,0:Breadcrumbs,2:Toc,2:TocResize,5:FeedbackCounter,0:VersionSelector,5:Feedback,3:epxfooter.2,3:Office,3:Breadcrumbs;/Areas/Epx/Content/Css:0,/Areas/Octagon/Content:1,/Areas/Epx/Library/Content:2,/Areas/Epx/Themes/Office/Content:3,/Areas/Epx/Themes/Shared/Content:4,/Areas/Epx/Shared/Content:5&amp;hashKey=471123558D539AE01D09B8A3C2E34935" xmlns="http://www.w3.org/1999/xhtml" />
         </head>

         <body>
            <xsl:apply-templates select="ProjectGroup" />
            <xsl:apply-templates select="Project" />
            <xsl:apply-templates select="File" />
         </body>
       </html>
   
   </xsl:template>

   <xsl:template match="ProjectGroup">
      
      <h1>Project Group <xsl:value-of select="FileName"/></h1>

      <p class="Header1Paragraph">
      
         <!-- Build the projects table -->
         <xsl:apply-templates select="Projects" />

      </p>

      <!-- Build the documentation section for each project -->
      <xsl:for-each select="Projects/Project">

         <!-- Apply template for Project -->
         <xsl:apply-templates select="."/>

      </xsl:for-each>
   
   </xsl:template>

   <xsl:template match="Project">
      <xsl:variable name="ProjectName"><xsl:value-of select="Name" /></xsl:variable>

      <h1>
         <a>
            <xsl:attribute name="name">
               <xsl:call-template name="ProjectBookmarkName">
                  <xsl:with-param name="ProjectName"><xsl:value-of select="Name" /></xsl:with-param>
               </xsl:call-template>
            </xsl:attribute>
         </a>
         <xsl:value-of select="Name"/> Reference
      </h1>
   
      <p>Filename: <xsl:value-of select="FileName"/></p>
<!--         <span class='PropertyName'>Type: </span><xsl:value-of select="Type"/><br/>
         <span class='PropertyName'>BuildFilename: </span><xsl:value-of select="BuildFileName"/><br/>-->

         <!-- Build the references table -->
<!--         <xsl:apply-templates select="References" />

         <br/>
-->      
      
	  
	 <xsl:apply-templates select="Files" >
		<xsl:with-param name="ProjectName"><xsl:value-of select="Name" /></xsl:with-param>
	 </xsl:apply-templates>

	 <xsl:for-each select="Files/File">
		<xsl:sort select="Type"/>
		<xsl:sort select="Name"/>
		
		<xsl:if test="./Properties/Property[Name = 'Instancing']/Value = 2" >
			<xsl:apply-templates select=".">
			   <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
			</xsl:apply-templates>
		</xsl:if>
	 </xsl:for-each>
   
      <br/>
      <hr/>
      <br/>
   
   </xsl:template>

   <xsl:template match="File">
      <xsl:param name="ProjectName"></xsl:param>   

      <xsl:variable name="FileName"><xsl:value-of select="Name" /></xsl:variable>

      <!-- Check if it is a true VB file -->
      <xsl:if test="Type != 'RelatedDocument' and Type != 'ResFile' ">
         <h1>
            <a>
               <xsl:attribute name="name">
                  <xsl:call-template name="FileBookmarkName">
                     <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
                     <xsl:with-param name="FileName"><xsl:value-of select="Name" /></xsl:with-param>
                  </xsl:call-template>
               </xsl:attribute>
            </a>

            <xsl:value-of select="Name"/>
            <xsl:if test="FileName != '' ">
               <xsl:text> (</xsl:text>
               <xsl:value-of select="FileName"/>
               <xsl:text>)</xsl:text>
            </xsl:if>
            <xsl:text> - </xsl:text>
            <xsl:apply-templates select="Type" />
         </h1>

         <p class="Header3Paragraph">

            <span class='PropertyName'>Comment: </span>

            <xsl:choose>
               <xsl:when test="count(CodeModule/CommentLines/CommentLine) = 0"> None<br/><br/></xsl:when>
               <xsl:otherwise>
                  <br/>
                  <br/>
                  <xsl:for-each select="CodeModule/CommentLines/CommentLine">
                     <xsl:value-of select="."/>
                     <br/>
                  </xsl:for-each>
                  <br/>
               </xsl:otherwise>
            </xsl:choose>

<!--            <span class='PropertyName'>Count of declaration lines: </span><xsl:value-of select="CodeModule/CountOfDeclarationLines"/><br/>
            <span class='PropertyName'>Count of lines: </span><xsl:value-of select="CodeModule/CountOfLines"/><br/>
-->      
            <!-- Include the list of properties -->
<!--            <xsl:apply-templates select="Properties" />-->

            <!-- If it is a file with visual interface, we include the list of controls -->
            <xsl:if test="Type = 'VBForm' or Type = 'VBMDIForm' or Type = 'UserControl' or 
                             Type = 'DocObject' or Type = 'PropPage' or Type = 'MSForm' ">

               <xsl:apply-templates select="Controls" />
         
            </xsl:if>

            <!-- Build the Interfaces table -->
            <xsl:apply-templates select="CodeModule/Interfaces" />

            <!-- Build the Events table -->
            <xsl:apply-templates select="CodeModule/Events" />

            <!-- Build the Procedures table -->
            <xsl:apply-templates select="CodeModule/Procedures">
               <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
               <xsl:with-param name="FileName"><xsl:value-of select="Name" /></xsl:with-param>
            </xsl:apply-templates>

            <br/>

            <!-- Build the documentation section for each procedure -->
            <xsl:for-each select="CodeModule/Procedures/Procedure">
               <xsl:sort select="Scope" />
               <xsl:sort select="Name" />

			   <xsl:if test="Scope = 'Public' and (Type='PropertyLet' or Type='PropertySet' or Type='PropertyGet')" >
				   <!-- Apply template for Procedure -->
				   <xsl:apply-templates select=".">
					  <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
					  <xsl:with-param name="FileName"><xsl:value-of select="$FileName" /></xsl:with-param>
				   </xsl:apply-templates>
			   </xsl:if>
            </xsl:for-each>

            <xsl:for-each select="CodeModule/Procedures/Procedure">
               <xsl:sort select="Scope" />
               <xsl:sort select="Name" />

			   <xsl:if test="Scope = 'Public' and (Type='Function' or Type='Subroutine')">
			   <!--<xsl:if test="Name != preceding-sibling::Procedure[position()=1]/Name">-->
<!--<hr/>BONX!			   <xsl:value-of select="preceding-sibling::Procedure[position()=1]/Name" /><hr/>-->
				   <!-- Apply template for Procedure -->
				   <xsl:apply-templates select=".">
					  <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
					  <xsl:with-param name="FileName"><xsl:value-of select="$FileName" /></xsl:with-param>
				   </xsl:apply-templates>
			   <!--</xsl:if>-->
			   </xsl:if>
            </xsl:for-each>

			</p>
      </xsl:if>
   
   </xsl:template>

   <xsl:template match="Procedure">
      <xsl:param name="ProjectName"></xsl:param>   
      <xsl:param name="FileName"></xsl:param>   

	  <h2 class="title">

		 <!-- Build a bookmark -->
		 <a>
			<xsl:attribute name="name">
			   <xsl:call-template name="ProcedureBookmarkName">
				  <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
				  <xsl:with-param name="FileName"><xsl:value-of select="$FileName" /></xsl:with-param>
				  <xsl:with-param name="ProcedureName"><xsl:value-of select="Name" /></xsl:with-param>
				  <xsl:with-param name="ProcedureType"><xsl:value-of select="Type" /></xsl:with-param>
			   </xsl:call-template>
			</xsl:attribute>
		 </a>

		 <xsl:value-of select="Name"/>
		 <xsl:text> - </xsl:text>
		 <xsl:apply-templates select="Type" />
		 <xsl:text> (</xsl:text>
		 <xsl:value-of select="$FileName" />
		 <xsl:text>)</xsl:text>

	  </h2>

	  <div class="cdclvSection">
		<div class="devdocvsbody">

			 <!-- Build some properties of the procedure-->
	<!--         <span class='PropertyName'>Type: </span><xsl:apply-templates select="Type" />
			 <br/>
			 <span class='PropertyName'>Scope: </span><xsl:value-of select="Scope"/>
			 <br/>
			 <span class='PropertyName'>Count of lines: </span><xsl:value-of select="CountOfLines"/>
			 <br/>-->
			   <xsl:for-each select="CommentLines/CommentLine">
				  <xsl:if test="starts-with(., ':!')" >
					  <xsl:value-of select="substring(., 3, 500)"/>
					  <xsl:text> </xsl:text>
				  </xsl:if>
			   </xsl:for-each>

			   <p><strong class="mainheaders">Syntax</strong></p>
			 <p class="signature">
				<strong>
					<em>expression</em>
					<xsl:text>.</xsl:text>
					<xsl:value-of select="Name"/>
					<xsl:text>(</xsl:text>
					<xsl:for-each select="Parameters/Parameter">
						<em><xsl:value-of select="Name" /></em>
						<xsl:if test="position() != last()">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
					<xsl:text>)</xsl:text>
	<!--				<xsl:value-of select="Declaration"/>-->
				</strong>
			 </p>
			 
			 <p><em>expression</em>
			 <xsl:text>   A variable that represents a </xsl:text>
			 <xsl:value-of select="$FileName" />
			 <xsl:text> object.</xsl:text>
			 </p>

			 <xsl:apply-templates select="Parameters" />
			 
			<xsl:if test="count(CommentLines/CommentLine) > 0">
			   <p><strong class='mainheaders'>Remarks</strong></p>
			   <xsl:for-each select="CommentLines/CommentLine">
				  <xsl:if test="starts-with(., '::')" >
					  <xsl:value-of select="substring(., 3, 500)"/>
					  <xsl:text> </xsl:text>
				  </xsl:if>
			   </xsl:for-each>
			</xsl:if>

		</div>
	  </div>
   </xsl:template>

   <xsl:template match="Projects">

      <span class='ListHeader'>Projects:</span>

      <table border="0" width="90%">

      <tr>
         <th>Name</th>
         <th>Filename</th>
         <th>Type</th>
      </tr>

      <xsl:for-each select="Project">

         <xsl:sort select="Type"/>
         <xsl:sort select="Name"/>
       
         <tr>
            <td>
               <!-- We add a hyperlink to a bookmark with information about of the project -->
               <a>
                  <xsl:attribute name="href">
                     <xsl:text>#</xsl:text>
                     <xsl:call-template name="ProjectBookmarkName">
                        <xsl:with-param name="ProjectName"><xsl:value-of select="Name" /></xsl:with-param>
                     </xsl:call-template>
                  </xsl:attribute>
                  <xsl:value-of select="Name" />
               </a>
            </td>
            <td><xsl:value-of select="FileName"/></td>
            <td><xsl:value-of select="Type"/></td>
         </tr>

       </xsl:for-each>

      </table>

   </xsl:template>

   <xsl:template match="Files">

      <xsl:param name="ProjectName"></xsl:param>   

	 <xsl:for-each select="File">
		<xsl:sort select="Type" />
		<xsl:sort select="Name" />
		
		<xsl:if test="Properties/Property[Name='Instancing']/Value = 2">	<!-- Just the public ones -->
		  <a>
			 <xsl:attribute name="href">
				<xsl:text>#</xsl:text>
				<xsl:call-template name="FileBookmarkName">
				   <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
				   <xsl:with-param name="FileName"><xsl:value-of select="Name" /></xsl:with-param>
				</xsl:call-template>
			 </xsl:attribute>
			 <xsl:value-of select="Name" />
			 <xsl:text> </xsl:text>
			<xsl:apply-templates select="Type"/>
		  </a>
		  <br/>
		</xsl:if>
	 </xsl:for-each>
   </xsl:template>

   <xsl:template match="References">

      <span class='ListHeader'>References:</span>

      <table border="0" width="90%">

      <tr>
         <th>Name</th>
         <th>Filename</th>
         <th>Description</th>
         <th>Type</th>
         <th>Version</th>
      </tr>
          
      <xsl:for-each select="Reference">

         <tr>
            <td><xsl:value-of select="Name"/></td>
            <td><xsl:value-of select="FileName"/></td>
            <td><xsl:value-of select="Description"/></td>
            <td><xsl:value-of select="Type"/></td>
            <td><xsl:value-of select="Major"/>.<xsl:value-of select="Minor"/></td>
         </tr>

      </xsl:for-each>

      </table>

   </xsl:template>

   <xsl:template match="Controls">

      <br/><span class='ListHeader'>Controls:</span>
     
      <table border="0" width="90%">
         
         <tr>
            <th>Name</th>
            <th>ProgID</th>
            <th>Caption</th>
         </tr>
            
         <xsl:for-each select="Control">
            <xsl:sort select="Name"/>
            <tr>
               <td><xsl:value-of select="Name"/></td>
               <td><xsl:value-of select="ProgId"/></td>
                  <td>
                     <xsl:choose>
                        <xsl:when test="Properties/Property[Name='Caption']/Value">
                           <xsl:text>"</xsl:text>
                           <xsl:value-of select="Properties/Property[Name='Caption']/Value" />
                           <xsl:text>"</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>n/a</xsl:otherwise>
                     </xsl:choose>
                  </td>
               </tr>
         </xsl:for-each>

      </table>

   </xsl:template>

   <xsl:template match="Events">
      <xsl:if test="Event != '' ">
         <h2>Events</h2>

         <xsl:for-each select="Event">
		   <xsl:value-of select="Name"/>
		   <br/>
		   <!--<xsl:value-of select="Declaration"/>-->
         </xsl:for-each>
      </xsl:if>
   </xsl:template>

   <xsl:template match="Interfaces">
      <xsl:if test="Interface != '' ">
         <h2>Implemented Interfaces</h2>

		<p>
         <xsl:for-each select="Interface">
		   <xsl:value-of select="."/>
		   <br/>
         </xsl:for-each>
		 </p>
      </xsl:if>

   </xsl:template>

   <xsl:template match="Procedures">
      <xsl:param name="ProjectName"></xsl:param>   
      <xsl:param name="FileName"></xsl:param>   
        
	 <xsl:if test="count(Procedure[Scope='Public' and (Type='PropertyLet' or Type='PropertySet' or Type='PropertyGet')])">
		<h2>Eigenschaften</h2>
		   <xsl:for-each select="Procedure">
			  <xsl:sort select="Scope" />
			  <xsl:sort select="Name" />
			  <xsl:sort select="Type" order="descending"/>	<!-- Set, Let, Get -->
			  
			  <xsl:if test="Scope='Public' and (Type='PropertyLet' or Type='PropertySet' or Type='PropertyGet')" >
			   <xsl:if test="Name != preceding-sibling::Procedure[position()=1]/Name">
				<a>
				   <xsl:attribute name="href">
					  <xsl:text>#</xsl:text>
					  <xsl:call-template name="ProcedureBookmarkName">
						 <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
						 <xsl:with-param name="FileName"><xsl:value-of select="$FileName" /></xsl:with-param>
						 <xsl:with-param name="ProcedureName"><xsl:value-of select="Name" /></xsl:with-param>
						 <xsl:with-param name="ProcedureType"><xsl:value-of select="Type" /></xsl:with-param>
					  </xsl:call-template>
				   </xsl:attribute>
				   <xsl:value-of select="Name" />
				</a>
				<xsl:text> - </xsl:text>
				<xsl:choose>
					<xsl:when test="Type='PropertySet'">Get/Set</xsl:when>
					<xsl:when test="Type='PropertyLet'">Get/Let</xsl:when>
					<xsl:when test="Type='PropertyGet'">read only</xsl:when>
				</xsl:choose>
			  <br/>
			  </xsl:if>
			  </xsl:if>

		  </xsl:for-each>
      </xsl:if>

	 <xsl:if test="count(Procedure[Scope='Public' and (Type='Function' or Type='Subroutine')])">
		<h2>Methods</h2>
		   <xsl:for-each select="Procedure">
			  <xsl:sort select="Scope" />
			  <xsl:sort select="Name" />
			  
			  <xsl:if test="Scope='Public' and (Type='Function' or Type='Subroutine')" >
				<a>
				   <xsl:attribute name="href">
					  <xsl:text>#</xsl:text>
					  <xsl:call-template name="ProcedureBookmarkName">
						 <xsl:with-param name="ProjectName"><xsl:value-of select="$ProjectName" /></xsl:with-param>
						 <xsl:with-param name="FileName"><xsl:value-of select="$FileName" /></xsl:with-param>
						 <xsl:with-param name="ProcedureName"><xsl:value-of select="Name" /></xsl:with-param>
						 <xsl:with-param name="ProcedureType"><xsl:value-of select="Type" /></xsl:with-param>
					  </xsl:call-template>
				   </xsl:attribute>
				   <xsl:value-of select="Name" />
				</a>
			  <br/>
			  </xsl:if>

		  </xsl:for-each>
      </xsl:if>
   </xsl:template>

   <xsl:template match="Parameters">
	 <p><strong class="mainheaders">Parameters</strong></p>

      <xsl:choose>
         <xsl:when test="count(Parameter) = 0"> None</xsl:when>

         <xsl:otherwise>
			<div class="tablesection">
			<table>
			<tbody>
				<tr>
					<th><strong>Name</strong></th>
					<th><strong>Required/Optional</strong></th>
					<th><strong>Data Type</strong></th>
					<th><strong>Description</strong></th>
				</tr>

				<xsl:for-each select="Parameter">
					<tr>
						<td class="mainsection"><em><xsl:value-of select="Name"/></em></td>
						<td class="mainsection">
							<xsl:choose>
								<xsl:when test="IsOptional = 'True'">Optional</xsl:when>
								<xsl:otherwise>Required</xsl:otherwise>
							</xsl:choose>
						</td>
						<td class="mainsection"><strong><xsl:value-of select="Type"/></strong></td>
						<td class="mainsection">
							<xsl:variable name="ParamDokuPrefix">
								<xsl:text>:@</xsl:text>
								<xsl:value-of select="Name" />
							</xsl:variable>
							<xsl:value-of select="substring(../../CommentLines/CommentLine[starts-with(., $ParamDokuPrefix)], string-length($ParamDokuPrefix)+2, 500)" />
						</td>
<!--						<xsl:choose>
						   <xsl:when test="IsByVal='True'">ByVal</xsl:when>
						   <xsl:when test="IsByVal='False'">ByRef</xsl:when>
						</xsl:choose>-->
					</tr>
               </xsl:for-each>

			</tbody>
			</table>
			</div>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template match="File/Type">

      <xsl:choose>

         <!-- Here you can localize the type to your language -->

         <xsl:when test=". = 'StdModule' ">Module</xsl:when>
         <xsl:when test=". = 'ClassModule' ">Class</xsl:when>
         <xsl:when test=". = 'MSForm' ">MSForm</xsl:when>
         <xsl:when test=". = 'ResFile' ">Resource File</xsl:when>
         <xsl:when test=". = 'VBForm' ">Form</xsl:when>
         <xsl:when test=". = 'VBMDIForm' ">MDI Form</xsl:when>
         <xsl:when test=". = 'PropPage' ">Property Page</xsl:when>
         <xsl:when test=". = 'UserControl' ">User Control</xsl:when>
         <xsl:when test=". = 'DocObject' ">User Document</xsl:when>
         <xsl:when test=". = 'RelatedDocument' ">Related Document</xsl:when>
         <xsl:when test=". = 'ActiveXDesigner' ">ActiveX Designer</xsl:when>
         <xsl:when test=". = 'VBADocument' ">VBA Document</xsl:when>

      </xsl:choose>

   </xsl:template>

   <xsl:template match="Procedure/Type">
      <xsl:choose>
         <xsl:when test=". = 'Subroutine' ">Sub</xsl:when>
         <xsl:when test=". = 'Function' ">Function</xsl:when>
         <xsl:when test=". = 'PropertyGet' ">Property Get</xsl:when>
         <xsl:when test=". = 'PropertyLet' ">Property Let</xsl:when>
         <xsl:when test=". = 'PropertySet' ">Property Set</xsl:when>
      </xsl:choose>
   </xsl:template>
   
   <xsl:template name="ProjectBookmarkName">
      <xsl:param name="ProjectName"></xsl:param>   

      <!-- Build a bookmark name with the pattern "ProjectName_Bookmark" -->
      <xsl:value-of select="$ProjectName" />
      <xsl:text>_Bookmark</xsl:text>

   </xsl:template>
 
   <xsl:template name="FileBookmarkName">

      <xsl:param name="ProjectName"></xsl:param>   
      <xsl:param name="FileName"></xsl:param>   

      <!-- Build a bookmark name with the pattern "ProjectName_FileName_Bookmark" -->
      <xsl:value-of select="$ProjectName" />
      <xsl:text>_</xsl:text>
      <xsl:value-of select="$FileName"/>
      <xsl:text>_Bookmark</xsl:text>

   </xsl:template>

   <xsl:template name="ProcedureBookmarkName">

      <xsl:param name="ProjectName"></xsl:param>   
      <xsl:param name="FileName"></xsl:param>   
      <xsl:param name="ProcedureName"></xsl:param>   
      <xsl:param name="ProcedureType"></xsl:param>   

      <!-- Build a bookmark name with the pattern "ProjectName_FileName_ProcedureName_ProcedureType_Bookmark" -->
      <xsl:value-of select="$ProjectName" />
      <xsl:text>_</xsl:text>
      <xsl:value-of select="$FileName"/>
      <xsl:text>_</xsl:text>
      <xsl:value-of select="$ProcedureName"/>
      <xsl:text>_</xsl:text>
      <xsl:value-of select="$ProcedureType"/>
      <xsl:text>_Bookmark</xsl:text>

   </xsl:template>

<!--   <xsl:template match="Properties">

      <br/><span class='ListHeader'>Properties:</span>
        
      <table border="0" width="90%">
            
         <tr>
            <th>Name</th>
            <th>Value</th>
         </tr>
          
         <xsl:for-each select="Property">
            <xsl:sort select="Name"/>
            <tr>
               <td><xsl:value-of select="Name"/></td>
               <td><xsl:value-of select="Value"/></td>
            </tr>
         </xsl:for-each>

      </table>

   </xsl:template>-->

</xsl:stylesheet>


